package com.wcs.exam.controller.auth;

import com.wcs.exam.common.base.Result;
import com.wcs.exam.controller.auth.biz.AuthUsersBiz;
import com.wcs.exam.controller.auth.req.*;
import com.wcs.exam.controller.auth.resp.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.web.bind.annotation.*;

/**
 * Auth-用户信息
 *
 * @author wcs
 * @since 2025-03-28
 */
@Tag(name = "Auth-用户相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/auth/users")
public class AuthUsersController {

    @NotNull
    private final AuthUsersBiz biz;

    @Operation(summary = "获取当前用户的基本信息")
    @GetMapping(value = "/view")
    public Result<AuthUsersResp> view() {
        return biz.view();
    }

    @Operation(summary = "更新当前用户的基本信息")
    @PostMapping(value = "/edit")
    public Result<String> edit(@RequestBody @Valid AuthUsersReq req) {
        return biz.edit(req);
    }

    @Operation(summary = "用户账号绑定微信")
    @PutMapping(value = "/wx/binding")
    public Result<String> wxBinding(@RequestBody AuthWxBindingReq req) throws WxErrorException {
        return biz.wxBinding(req);
    }

    @Operation(summary = "用户账号解绑微信")
    @GetMapping(value = "/wx/unbind")
    public Result<String> wxUnbind() {
        return biz.wxUnbind();
    }

    @Operation(summary = "用户强制实名认证检测")
    @GetMapping(value = "/certification/compulsory")
    public Result<Boolean> certificationCompulsory() {
        return biz.certificationCompulsory();
    }

    @Operation(summary = "用户实名认证次数查询")
    @GetMapping(value = "/certification/count")
    public Result<AuthUsersCertificationCountResp> certificationCount() {
        return biz.certificationCount();
    }

    @Operation(summary = "APP实名认证", description = "返回相关参数")
    @PostMapping(value = "/get/app/face/params")
    public Result<AuthUsersAppFaceParamsResp> getAppFaceParams(@RequestBody @Valid AuthUsersAppFaceParamsReq req) {
        return biz.getAppFaceParams(req);
    }

    @Operation(summary = "H5实名认证", description = "返回认证Url")
    @PostMapping(value = "/detect/auth/url")
    public Result<AuthUsersDetectAuthUrlResp> detectAuthUrl(@RequestBody AuthUsersDetectAuthUrlReq req) {
        return biz.detectAuthUrl(req);
    }

    @Operation(summary = "用户实名认证接口")
    @PostMapping(value = "/certification")
    public Result<AuthUsersCertificationResultResp> certification(@RequestBody @Valid AuthUsersCertificationReq req) {
        return biz.certification(req);
    }
}
